package com.example.JavaWebApi.core.neo4j;

import com.example.JavaWebApi.model.neo4j.result.RelationVo;
import org.neo4j.driver.Value;
import org.neo4j.driver.Values;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.convert.converter.Converter;
import org.springframework.data.neo4j.core.convert.Neo4jConversions;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

/**
 * @program: java-web-api
 * @description:
 * @author: 杨泽
 * @create: 2023-09-14 14:56
 */
@Configuration
public class Neo4jConfiguration {
    static class Convert implements Converter<RelationVo, Value> {

        @Override
        public Value convert(RelationVo source) {
            Map<String,Object> convertedPerson =new HashMap<>();
            convertedPerson.put("startId",source.getStartId());
            convertedPerson.put("endId",source.getEndId());
            convertedPerson.put("relation",source.getRelation());
            return Values.value(convertedPerson);
        }
        @Bean
        public Neo4jConversions neo4jConversions() {
            return new Neo4jConversions(Arrays.asList(new Convert()));
        }
    }
}